/**
 * 
 */
package com.manage.action;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;


import com.action.AbstractAction;
import com.manage.cache.AppPointOfBillingManager;
import com.manage.cache.ConfirmTemplateManager;
import com.manage.cache.PayVersionManager;
import com.manage.model.ConfirmTemplate;
import com.manage.model.PayVersion;
import com.util.Util;


public class PayVersionAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	
	public PayVersionAction()
	{
		logger = Logger.getLogger(this.getClass());
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private List<PayVersion> list;
	private PayVersion       model;
	private String        type;
	private List<ConfirmTemplate> ctlist;
	
	public String list()
	{
		logger.debug("list PayVersionAction");
		ctlist = ConfirmTemplateManager.getInstance().getConfirmTemplates();
		list = PayVersionManager.getInstance().getPayVersions();
		return SUCCESS;
	}
	
	public String show()
	{
		ctlist = ConfirmTemplateManager.getInstance().getConfirmTemplates();
		if (model.getId() >= 0)
		{
			model = PayVersionManager.getInstance().getPayVersion(model.getId());
			type = "update";
		}
		else
		{
			model.setId(-1);
			type = "insert";
		}

		return SUCCESS;
	}
	
	public String save()
	{
		if(type.equals("insert"))
		{
			model.setCreatedate(Util.dateToString(new Date()));
			model.setCreateuser(operator.getName());
			
			//判断code是否存在，存在就直接返回
			if(PayVersionManager.getInstance().isVersionCode(model.getVersioncode()))
			{
				addActionError("版本号已经存在！");
				return SUCCESS;
			}
		}
		PayVersionManager.getInstance().savePayVersion(operator, type, model);
		return SUCCESS;
	}

	public List<PayVersion> getList() {
		return list;
	}

	public void setList(List<PayVersion> list) {
		this.list = list;
	}

	public PayVersion getModel() {
		return model;
	}

	public void setModel(PayVersion model) {
		this.model = model;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<ConfirmTemplate> getCtlist() {
		return ctlist;
	}

	public void setCtlist(List<ConfirmTemplate> ctlist) {
		this.ctlist = ctlist;
	}
	
}
